package behavioral.iterator;

public class BookShelfIterator implements Iterator {
	private BookShelf _bookShelf;
	private int _index;
	public BookShelfIterator(BookShelf bookShelf) {
		this._bookShelf = bookShelf;
		this._index = 0;
	}
	@Override
	public Object first() {
		return _bookShelf.getBookAt(0);
	}
	@Override
	public Object next() {
		if(!isDone()) {
			Book book = _bookShelf.getBookAt(_index);
			_index++;
			return book;
		} else {
			return null;
		}
	}
	@Override
	public boolean isDone() {
		return _index > _bookShelf.getLength();
	}
	@Override
	public Object currentItem() {
		return _bookShelf.getBookAt(_index);
	}
	@Override
	public boolean hasNext() {
		if(_index < _bookShelf.getLength()) {
			return true;
		} else {
			return false;
		}
	}
}
